package com.yy.controller;

import com.yy.entity.Employee;
import com.yy.service.EmployeeService;
import com.yy.utils.MD5Utils;
import com.yy.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;

/**
 * create by KongFuning on 2022/7/30
 */
@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /*
    * 登录
    * */
    @PostMapping("/login")
    public R login(HttpServletRequest request,@RequestBody Employee employee){
        return employeeService.login(request,employee);
    }

    /*
    * 登出
    * */
    @PostMapping("/logout")
    public R logout(HttpServletRequest request){
        return employeeService.logout(request);
    }

    /*
    * 分页查询
    * */
    @GetMapping("/page")
    public R getMemberList(Integer page,Integer pageSize,String name){
       return employeeService.pageEmployees(page,pageSize,name);
    }

    /*
    * 添加员工
    * */
    @PostMapping
    public R save(@RequestBody Employee employee){
        return employeeService.saveEmployee(employee);
    }

    /*
    * 编辑员工反查详情
    * */
    @GetMapping("/{id}")
    public R toUpdate(@PathVariable String id){
        return employeeService.toUpdate(id);
    }

    /*
     * 修改员工信息 + 员工状态启用：禁用接口
     * */
    @PutMapping
    public R update(@RequestBody Employee employee){
        return employeeService.updateEmployee(employee);
    }


}
